package com.hrp.analyzer.model;

import androidx.annotation.NonNull;

import java.io.Serializable;
import java.util.Objects;

/**
 * 章节信息
 *
 * @author hrp
 * @date 2020/12/20 6:24 下午
 */

public class Chapter implements Serializable {
    /**
     * 章节序号
     */
    private int order = -1;
    /**
     * 章节名字
     */
    private String name;
    /**
     * 章节url
     */
    private String url;
    /**
     * 正文
     */
    private String content;
    private Long from;
    private Long to;
    /**
     * 章节状态
     */
    private ChapterState state = ChapterState.INIT;

    public Chapter(String name, String url) {
        this.name = name;
        this.url = url;
    }

    /**
     * 只根据URL分别唯一
     *
     * @param o other
     * @return /
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Chapter chapter = (Chapter) o;
        return Objects.equals(url, chapter.url);
    }

    @Override
    public int hashCode() {
        return Objects.hash(url);
    }

    @NonNull
    @Override
    public String toString() {
        return String.format("name=%s,url=%s", name, url);
    }

    /**
     * 是否已经被下载
     *
     * @return true 已经下载
     */
    public boolean downloaded() {
        return state == ChapterState.DOWNLOADED;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Long getFrom() {
        return from;
    }

    public void setFrom(Long from) {
        this.from = from;
    }

    public Long getTo() {
        return to;
    }

    public void setTo(Long to) {
        this.to = to;
    }

    public ChapterState getState() {
        return state;
    }

    public void setState(ChapterState state) {
        this.state = state;
    }
}
